<?php
class ml_biz_pinboard{

    /**
     *
     * 输入content数组，输出组装好的pinboard HTML数组
     * @param unknown_type $content数组
     *
     */
    private $aRid = array();
    private $aUid = array();
    private $aNicks = array();
    private $aAttitude = array();
    private $aLikeCnt = array();
    private $aCmtCnt = array();
    private $aQuoteCnt = array();//pin宝贝被转采数
    private $redis;//redis对象实例（防止多次实例化）
    private $uid;
    private $uniqueData=array();//统一后的数组
    private $is_share;
    private $ifme;
    /**
     *
     * 输入content数组，输出组装好的pinboard HTML数组
     * @param unknown_type $aData数组
     * @param unknown_type 取消关注deleteType=2,其他传=1
     * @param unknown_type $uid
     * @param unknown_type 是否是我的最爱，最爱的话不用判断是否表过态
     * @param unknown_type $ifme是否需要显示关闭
     * @param unknown_type $comment评论
     *
     */
    public function __construct($aData=array(),$uid,$ifme=false,$is_share=true,$comment=array()){

        $this->redis=new ml_model_rdsCount();
        $this->uniqueData=$this->getUidRid($aData, $comment);
        $this->uid=$uid;
        $this->ifme=$ifme;
        $this->is_share=$is_share;

        $this->get_cnt();

        if($is_share||!$ifme&&!$is_share)//是我的分享或者是他人的最爱
        {
            $this->get_attitude();
        }

        $this->get_comment();
        $this->get_ColCnt();


    }
    public function getUidRid($aData,&$comment){
        if (empty($aData))
        return false;
        foreach ($aData as $value) {
            $this->aUid[]=$value['uid'];
            $this->aRid[]=$value['rid'];
        }
        if(!empty($comment)){//带评论
            foreach ($comment as $v_com) {
                $this->aUid[]=$v_com['uid'];
            }
            $this->aUid=array_unique($this->aUid);
            $this->get_nick();
            $this->uniqueData($aData, $comment);
            return $comment;
        }else{
            $this->get_nick();
            return $aData;
        }

    }
    public function uniqueData($aData,&$comment){

        foreach ($comment as &$content) {
            $tmp_uid=ml_tool_resid::resid2uid($content['rid']);//作者uid
            $content['is_quote']=true;//转采形式
            $content['attitude_score'] = $this->aAttitude[$content['rid']];
            $content['quote_info']=array('uid'=>$content['uid'],'content'=>$content['comment'],'nick'=>Tool_string::un_html($this->aNicks[$content['uid']]));
            $content['uid']=$tmp_uid;//作者uid
            $content['type_xrank']=$aData[$content['rid']]['type_xrank'];
            $content['pic_id']=$aData[$content['rid']]['pic_id'];
            $content['gd_title']=$aData[$content['rid']]['gd_title'];
            $content['gd_price']=$aData[$content['rid']]['gd_price'];
            $content['content']=$aData[$content['rid']]['content'];
        }

    }
    public function output(){

        foreach ($this->uniqueData as &$content) {

            $content['nick']=$this->aNicks[$content['uid']];
            $content['deleteType']="deleteType=1";
            $content['like_cnt'] = intval($this->aLikeCnt[$content['rid']]);
            $content['cmt_cnt'] = intval($this->aCmtCnt[$content['rid']]);
            $content['quote_cnt'] = intval($this->aQuoteCnt[$content['rid']]);
            if (!$this->is_share&&$this->ifme){//是最爱  并且是自己
                $content['is_attitude'] = true;
            }else{
                $content['is_attitude'] = isset($this->aAttitude[$content['rid']]) ? true : false;
            }
            $content['attitude_score'] = $this->aAttitude[$content['rid']];
        }

        return ml_tool_pinOutput::parsePinboardTpl($this->uniqueData,$this->ifme);

    }

    public function get_nick()
    {
        $this->aNicks = ml_tool_nick::uids2nicks($this->aUid);

        //        $oAccount = new ml_model_dbUserAccount();
        //        $rs = $oAccount->getNicksByUids($this->aUid);
        //        $this->aNicks = $oAccount->get_data();
    }
    public function get_cnt()
    {
        $rs = $this->redis->getAttitudeCount($this->aRid);
        /**
         * @todo
         */
        $this->aLikeCnt = $this->redis->get_data();

    }
    public function get_attitude()
    {
        if($this->uid)
        {
            $oIlike = new ml_model_dbILike();
            $rs = $oIlike->getListByUidRids($this->uid , $this->aRid);
            $this->aAttitude = Tool_array::format_2d_array($oIlike->get_data() , 'content_rid' , Tool_array::FORMAT_VALUE2VALUE2 ,'attitude');
        }
    }
    public function  get_comment(){
        $rs = $this->redis->getCommentCount($this->aRid);
        /**
         * @todo
         */
        $this->aCmtCnt = $this->redis->get_data();

    }
    public function  get_ColCnt(){
        $rs = $this->redis->getColCnt($this->aRid);
        /**
         * @todo
         */
        $this->aQuoteCnt = $this->redis->get_data();

    }

}
?>